import Vue from 'vue'
import VueRouter from 'vue-router'
const Login = () => import(/* wepackChunkName: 'login' */'@/views/login')
const Register = () => import(/* wepackChunkName: 'register' */'@/views/register')
const Forget = () => import(/* wepackChunkName: 'forget' */'@/views/forget')

Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: Login
  },
  {
    path: '/register',
    name: 'register',
    component: Register,
    beforeEnter (to, from, next) {
      if (from.name === 'login') {
        next()
      } else {
        next('/login')
      }
    }
  },
  {
    path: '/forget',
    name: 'forget',
    component: Forget
  }
]

const router = new VueRouter({
  routes
})

export default router
